//
//  DoctorHospitalListVC.m
//  Doctor
//
//  Created by 阳光 on 16/10/10.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "DoctorHospitalListVC.h"
#import "DoctorHospitalListCell.h"
#import "DoctorHospitalListModel.h"
#import "AddTimeListVC.h"


static NSString *doctorHospitalListCellIdentifier=@"DoctorHospitalListCellIdentifier";

@interface DoctorHospitalListVC ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *doctorHospitalListTableView;

@property(nonatomic,strong)NSMutableArray *doctorHospitalListArr;

@end

@implementation DoctorHospitalListVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"视频预约";
    
    _doctorHospitalListArr=[NSMutableArray array];
    
    [self initTableView];
    
    // 获取医生所在的医院
    [self getDoctorHospitalListData];

}

-(void)getDoctorHospitalListData
{
    NSDictionary *dic=@{
                        @"doctor_id":[Util getUserDefaultObjectForKey:@"id"]
                        };
    __weak typeof(self) weakSelf=self;
   [QBRequest DoctorHospitalListWithDic:dic Success:^(id res)
    {
        if ([res[@"info"]count]>0)
        {
            weakSelf.doctorHospitalListArr=[DoctorHospitalListModel mj_objectArrayWithKeyValuesArray:res[@"info"]];
        }
        else
        {
            [self.view makeToast:@"暂无医生所在医院" duration:1.0 position:CSToastPositionCenter];
        }
        
        [weakSelf.doctorHospitalListTableView reloadData];
        
        [weakSelf.doctorHospitalListTableView.mj_header endRefreshing];
       
   } failure:^(NSString *error)
    {
       
   }];
    
}

-(void)initTableView
{
    // _doctorHospitalListTableView
    _doctorHospitalListTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,0,APPW,APPH-64) style:UITableViewStylePlain];
    _doctorHospitalListTableView.delegate=self;
    _doctorHospitalListTableView.dataSource=self;
    _doctorHospitalListTableView.showsVerticalScrollIndicator=NO;
    _doctorHospitalListTableView.backgroundColor=MAIN_BACK_COLOR;
    _doctorHospitalListTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_doctorHospitalListTableView];
    [_doctorHospitalListTableView registerClass:[DoctorHospitalListCell class] forCellReuseIdentifier:doctorHospitalListCellIdentifier];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.doctorHospitalListArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DoctorHospitalListCell *cell=[tableView dequeueReusableCellWithIdentifier:doctorHospitalListCellIdentifier];
    cell.doctorHospitalListModel=self.doctorHospitalListArr[indexPath.row];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    // 添加预约时间
    AddTimeListVC *addTimeListVC=[AddTimeListVC new];
    addTimeListVC.addType=@"addType";
    DoctorHospitalListModel *doctorHospitalListModel=self.doctorHospitalListArr[indexPath.row];
    addTimeListVC.hospitalID=doctorHospitalListModel.ID;
    [self.navigationController pushViewController:addTimeListVC animated:NO];
    
}


@end
